public class Solution {
    //最大连续1的个数|||
    public int longestOnes(int[] nums, int k) {
        //转换为最长子串（0的个数小于k）
        int left = 0;
        int right = 0;
        int n = nums.length;
        int ret = 0;
        int count = 0;
        while(right < n) {
            //进入窗口
            if(nums[right] == 0) {
                count++;
            }
            right++;
            while(count > k) {
                if(nums[left] == 0) {
                    count--;
                }
                left++;
            }
            ret = Math.max(ret, right - left);
        }
        return ret;
    }
}
